$(function () {
    // 1. 获取元素 
    var youSpan = document.getElementById("you");


    $("#btn").click(function () {
        var account = $("#user").val();
        var pwd = $("#pwd").val();
        if (account && pwd) {
            login_account({ account, pwd }).then(({ status, msg, userval }) => {
                if (status) {
                    if ($("#isrem").prop("checked") == true) {
                        setcookie("lgc", userval, 31);
                    }
                    else {
                        setcookie("lgc", userval);
                    }

                    var url = urlParse();
                    var { returnrul } = url;
                    if (returnrul) {
                        location.href = decodeURIComponent(returnrul);
                    } else {
                        location.href = "./index.html";
                    }

                } else {
                    youSpan.innerText = msg;
                    youSpan.style.color = "red"
                    youSpan.style.fontSize = "12px"
                }
            }).catch(error => {
                throw error;
            })
        }

    })

    $(".eye1").click(function () {
        console.log(this);
        $("#pwd").prop("type", "text")
        $(this).css({ display: "none" })
        $(".eye2").css({ display: "inline-block" })
    })

    $(".eye2").click(function () {
        $("#pwd").prop("type", "password")
        $(this).css({ display: "none" })
        $(".eye1").css({ display: "inline-block" })
    })


})

function urlParse() {
    var search = location.search;
    var data = {};
    if (search) {  //从注册页跳转过来  => 有数据
        var str = search.substring(1);
        var list = str.split("&");
        // console.log(list);
        list.forEach(function (item) {
            var key = item.split("=")[0];
            var val = item.split("=")[1];
            data[key] = val;
        })
    }
    return data;
}
